﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Sector7.Medical.EntityType;
using Sector7.Framework.DB;
using Sector7.Medical.DAO.Standard;
using Sector7.Medical.Consts;
using Sector7.Framework.Core;
using Sector7.Framework.Enums;
using Sector7.Framework.EntityType;
using Sector7.Framework.DAO.Standard;
using Sector7.Medical.Enums;

namespace Sector7.Medical.Services
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码和配置文件中的类名“InformationService”。
    public class InformationService : IInformationService
    {        

        public List<M7_DrugType> GetDrugTypeList()
        {
            return DAOFactory.GetDAO<DrugTypeDAO>().ReadAllByFlags(C_DrugTypeFlags.PHYSICAL);
        }

        public int AddUnit(M7_Unit unit)
        {
            object result = DAOFactory.GetDAO<UnitDAO>().Create(unit);
            return Convert.ToInt32(result);
        }

        public List<M7_Unit> GetUnitList()
        {
            return DAOFactory.GetDAO<UnitDAO>().ReadAll();
        }

        public int UpdateUnit(EntityDeltaBase delta)
        {
            return DAOFactory.GetDAO<UnitDAO>().Update(delta);
        }

        public int DeleteUnit(int unitId)
        {
            return DAOFactory.GetDAO<UnitDAO>().Delete(unitId);
        }

        public int AddDrugType(M7_DrugType drugType)
        {
            object result = DAOFactory.GetDAO<DrugTypeDAO>().Create(drugType);
            return Convert.ToInt32(result);
        }

        public int UpdateDrugType(EntityDeltaBase delta)
        {
            return DAOFactory.GetDAO<DrugTypeDAO>().Update(delta);
        }

        public int DeleteDrugType(int drugTypeId)
        {
            return DAOFactory.GetDAO<DrugTypeDAO>().Delete(drugTypeId);
        }

        public List<M7_Unit> GetUnitListByFlags(int flags)
        {
            return DAOFactory.GetDAO<UnitDAO>().ReadAll(flags);
        }

        public List<M7_DrugForm> GetDrugFormList()
        {
            return DAOFactory.GetDAO<DrugFormDAO>().ReadAll();
        }

        public int CountByDrugName(string drugName)
        {
            return DAOFactory.GetDAO<DrugDAO>().Count(drugName);
        }

        public long AddDrug(M7_Drug drug)
        {
            object result = DAOFactory.GetDAO<DrugDAO>().Create(drug);
            return Convert.ToInt32(result);
        }

        public List<M7_Drug> GetDrugListByNatureTypeId(int natureTypeId)
        {
            return DAOFactory.GetDAO<DrugDAO>().ReadAll(natureTypeId, DrugPropertyType.Spec);
        }

        public List<M7_Drug> GetDrugListByKeywords(string keywords)
        {
            return DAOFactory.GetDAO<DrugDAO>().ReadAll(keywords, DrugPropertyType.Spec | DrugPropertyType.SpecList | DrugPropertyType.Price);
        }

        public int UpdateDrug(EntityDeltaBase delta)
        {
            return DAOFactory.GetDAO<DrugDAO>().Update(delta);
        }

        public List<M7_DrugRegType> GetDrugRegTypeList()
        {
            return DAOFactory.GetDAO<DrugRegTypeDAO>().ReadAll();
        }

        public int DeleteDrug(long drugId)
        {
            return DAOFactory.GetDAO<DrugDAO>().Delete(drugId);
        }

        /// <summary>
        /// 根据科室标志获取所有科室信息
        /// </summary>
        /// <param name="flags">科室标志</param>
        /// <returns></returns>
        public List<M7_Department> GetDepartmentList(int flags)
        {
            return DAOFactory.GetDAO<DepartmentDAO>().ReadAll(flags);
        }

        public List<M7_Department> GetDepartmentListByComflags(int comflags)
        {
            return DAOFactory.GetDAO<DepartmentDAO>().ReadAllByComflags(comflags);
        }

        public List<M7_Vendor> GetVendorList()
        {
            return DAOFactory.GetDAO<VendorDAO>().ReadAll();
        }

        public object AddVendor(M7_Vendor vendor)
        {
            return DAOFactory.GetDAO<VendorDAO>().Create(vendor);
        }

        public int SetVendor(EntityDeltaBase delta)
        {
            return DAOFactory.GetDAO<VendorDAO>().Update(delta);
        }

        public int DeleteVendor(long vendorId)
        {
            return DAOFactory.GetDAO<VendorDAO>().Delete(vendorId);
        }

        /// <summary>
        /// 添加科室
        /// </summary>
        /// <param name="department">科室信息</param>
        /// <returns></returns>
        public object AddDepartment(M7_Department department)
        {
            object result = DAOFactory.GetDAO<DepartmentDAO>().Create(department);
            return result;
        }

        /// <summary>
        /// 编辑科室
        /// </summary>
        /// <param name="department">科室信息</param>
        /// <returns></returns>
        public int UpdateDepartment(EntityDeltaBase delta)
        {
            return DAOFactory.GetDAO<DepartmentDAO>().Update(delta);
        }

        /// <summary>
        /// 编辑二级科室Flags
        /// </summary>
        /// <param name="parentDeptId">一级科室ID</param>
        /// <param name="flags">标志</param>
        /// <returns></returns>
        public int UpdateSubDepartmentFlags(int parentDeptId, int flags)
        {
            return DAOFactory.GetDAO<DepartmentDAO>().UpdateSubDepartmentFlags(parentDeptId, flags);
        }

        /// <summary>
        /// 删除科室
        /// </summary>
        /// <param name="departmentId">科室信息ID</param>
        /// <returns></returns>
        public int DeleteDepartment(int departmentId)
        {
            return DAOFactory.GetDAO<DepartmentDAO>().Delete(departmentId);
        }

        /// <summary>
        /// 获取所有病区信息
        /// </summary>
        /// <returns></returns>
        public List<M7_SickArea> GetSickAreaList()
        {
            return DAOFactory.GetDAO<SickAreaDAO>().ReadAll();
        }

        /// <summary>
        /// 添加病区
        /// </summary>
        /// <param name="area">病区信息</param>
        /// <returns></returns>
        public object AddSickArea(M7_SickArea area)
        {
            object result = DAOFactory.GetDAO<SickAreaDAO>().Create(area);
            return result;
        }

        /// <summary>
        /// 编辑病区
        /// </summary>
        /// <param name="delta">病区信息</param>
        /// <returns></returns>
        public int UpdateSickArea(EntityDeltaBase delta)
        {
            return DAOFactory.GetDAO<SickAreaDAO>().Update(delta);
        }

        /// <summary>
        /// 删除病区
        /// </summary>
        /// <param name="areaId">病区ID</param>
        /// <returns></returns>
        public int DeleteSickArea(int areaId)
        {
            return DAOFactory.GetDAO<SickAreaDAO>().Delete(areaId);
        }

        #region ///SickRoom
        /// <summary>
        /// 获取所病房信息
        /// </summary>
        /// <returns></returns>
        public List<M7_SickRoom> GetSickRoomList()
        {
            return DAOFactory.GetDAO<SickRoomDAO>().ReadAll();
        }

        /// <summary>
        /// 添加病房
        /// </summary>
        /// <param name="room">病房信息</param>
        /// <returns></returns>
        public object AddSickRoom(M7_SickRoom room)
        {
            object result = DAOFactory.GetDAO<SickRoomDAO>().Create(room);
            return result;
        }

        /// <summary>
        /// 编辑病房
        /// </summary>
        /// <param name="delta">病房信息</param>
        /// <returns></returns>
        public int UpdateSickRoom(EntityDeltaBase delta)
        {
            return DAOFactory.GetDAO<SickRoomDAO>().Update(delta);
        }

        /// <summary>
        /// 删除病房
        /// </summary>
        /// <param name="roomId">病房ID</param>
        /// <returns></returns>
        public int DeleteSickRoom(int roomId)
        {
            return DAOFactory.GetDAO<SickRoomDAO>().Delete(roomId);
        }
        #endregion

        #region ///SickBed
        /// <summary>
        /// 获取所病床信息
        /// </summary>
        /// <returns></returns>
        public List<M7_SickBed> GetSickBedList()
        {
            return DAOFactory.GetDAO<SickBedDAO>().ReadAll();
        }

        /// <summary>
        /// 根据病区获取所有病床信息
        /// </summary>
        /// <param name="areaId"></param>
        /// <returns></returns>
        public List<M7_SickBed> GetSickBedListByAreaId(int areaId)
        {
            return DAOFactory.GetDAO<SickBedDAO>().ReadAllByAreaId(areaId);
        }

        /// <summary>
        /// 根据病区和科室获取所有病床信息
        /// </summary>
        /// <param name="areaId"></param>
        /// <param name="deptId"></param>
        /// <returns></returns>
        public List<M7_SickBed> GetSickBedListByAreaDeptId(int areaId, int deptId)
        {
            return DAOFactory.GetDAO<SickBedDAO>().ReadAllByAreaDeptId(areaId, deptId);
        }

        /// <summary>
        /// 添加病床
        /// </summary>
        /// <param name="bed">病床信息</param>
        /// <returns></returns>
        public object AddSickBed(M7_SickBed bed)
        {
            object result = DAOFactory.GetDAO<SickBedDAO>().Create(bed);
            return result;
        }

        /// <summary>
        /// 编辑病床
        /// </summary>
        /// <param name="bed">病床信息</param>
        /// <returns></returns>
        public int UpdateSickBed(M7_SickBed bed)
        {
            return DAOFactory.GetDAO<SickBedDAO>().Update(bed);
        }

        /// <summary>
        /// 删除病床
        /// </summary>
        /// <param name="bedId">病床ID</param>
        /// <returns></returns>
        public int DeleteSickBed(int bedId)
        {
            return DAOFactory.GetDAO<SickBedDAO>().Delete(bedId);
        }
        #endregion

        #region ///Sick BedLevel
        /// <summary>
        /// 获取所有病床等级信息
        /// </summary>
        /// <returns></returns>
        public List<M7_SickBedLevel> GetSickBedLevelList()
        {
            return DAOFactory.GetDAO<SickBedLevelDAO>().ReadAll();
        }

        /// <summary>
        /// 添加病床等级信息
        /// </summary>
        /// <param name="bedLevel">病床等级信息</param>
        /// <returns></returns>
        public object AddSickBedLevel(M7_SickBedLevel bedLevel)
        {
            object result = DAOFactory.GetDAO<SickBedLevelDAO>().Create(bedLevel);
            return result;
        }

        /// <summary>
        /// 编辑病床等级信息
        /// </summary>
        /// <param name="delta">病床等级信息</param>
        /// <returns></returns>
        public int UpdateSickBedLevel(EntityDeltaBase delta)
        {
            return DAOFactory.GetDAO<SickBedLevelDAO>().Update(delta);
        }

        /// <summary>
        /// 删除病床等级信息
        /// </summary>
        /// <param name="bedLevelId">病床等级信息ID</param>
        /// <returns></returns>
        public int DeleteSickBedLevel(int bedLevelId)
        {
            return DAOFactory.GetDAO<SickBedLevelDAO>().Delete(bedLevelId);
        }
        #endregion

        #region ///ChargeItems

        /// <summary>
        /// 获取收费项目
        /// </summary>
        /// <returns></returns>
        public M7_ChargeItem GetChargeItem(int chargItemId)
        {
            return DAOFactory.GetDAO<ChargeItemDAO>().ReadItem(chargItemId);
        }

        /// <summary>
        /// 获取所有收费项目
        /// </summary>
        /// <returns></returns>
        public List<M7_ChargeItem> GetChargeItemList()
        {
            return DAOFactory.GetDAO<ChargeItemDAO>().ReadAllItems();
        }

        /// <summary>
        /// 添加收费项信息
        /// </summary>
        /// <param name="chargeItem">收费项信息</param>
        /// <returns></returns>
        public object AddChargeItem(M7_ChargeItem chargeItem)
        {
            return DAOFactory.GetDAO<ChargeItemDAO>().Create(chargeItem);
        }

        /// <summary>
        /// 编辑收费项信息
        /// </summary>
        /// <param name="chargeItem">收费项信息</param>
        /// <returns></returns>
        public int UpdateChargeItem(EntityDeltaBase delta)
        {
            return DAOFactory.GetDAO<ChargeItemDAO>().Update(delta);
        }

        /// <summary>
        /// 删除收费项信息
        /// </summary>
        /// <param name="itemId">收费项信息编号</param>
        /// <returns></returns>
        public int DeleteChargeItem(int itemId)
        {
            return DAOFactory.GetDAO<ChargeItemDAO>().Delete(itemId);
        }
        #endregion

        #region ///RegistryFee
        /// <summary>
        /// 获取所有挂号费信息
        /// </summary>
        /// <returns></returns>
        public List<M7_RegistryFee> GetRegistryFeeList()
        {
            return DAOFactory.GetDAO<RegistryFeeDAO>().ReadAll();
        }

        /// <summary>
        /// 添加挂号费信息
        /// </summary>
        /// <param name="regigstryFee">挂号费信息</param>
        /// <returns></returns>
        public object AddRegistryFee(M7_RegistryFee regigstryFee)
        {
            return DAOFactory.GetDAO<RegistryFeeDAO>().Create(regigstryFee);
        }

        /// <summary>
        /// 编辑挂号费信息
        /// </summary>
        /// <param name="delta">挂号费信息</param>
        /// <returns></returns>
        public int UpdateRegistryFee(EntityDeltaBase delta)
        {
            return DAOFactory.GetDAO<RegistryFeeDAO>().Update(delta);
        }

        /// <summary>
        /// 删除挂号费信息
        /// </summary>
        /// <param name="feeId">挂号费信息编号</param>
        /// <returns></returns>
        public int DeleteRegistryFee(int feeId)
        {
            return DAOFactory.GetDAO<RegistryFeeDAO>().Delete(feeId);
        }
        #endregion

        /// <summary>
        /// 获取所有员工组信息
        /// </summary>
        /// <returns></returns>
        public List<M7_EmployeeGroup> GetEmployeeGroupList()
        {
            return DAOFactory.GetDAO<EmployeeGroupDAO>().ReadAll();
        }

        /// <summary>
        /// 添加员工组
        /// </summary>
        /// <param name="employeeGroup">员工组信息</param>
        /// <returns></returns>
        public object AddEmployeeGroup(M7_EmployeeGroup employeeGroup)
        {
            return DAOFactory.GetDAO<EmployeeGroupDAO>().Create(employeeGroup);
        }

        /// <summary>
        /// 编辑员工组
        /// </summary>
        /// <param name="delta">员工组信息</param>
        /// <returns></returns>
        public int UpdateEmployeeGroup(EntityDeltaBase delta)
        {
            return DAOFactory.GetDAO<EmployeeGroupDAO>().Update(delta);
        }

        /// <summary>
        /// 删除员工组
        /// </summary>
        /// <param name="employeeGroupId">员工组ID</param>
        /// <returns></returns>
        public int DeleteEmployeeGroup(int employeeGroupId)
        {
            return DAOFactory.GetDAO<EmployeeGroupDAO>().Delete(employeeGroupId);
        }

        /// <summary>
        /// 获取所有员工信息
        /// </summary>
        /// <returns></returns>
        public List<M7_Employee> GetEmployeeList()
        {
            return DAOFactory.GetDAO<EmployeeDAO>().ReadAll();
        }

        /// <summary>
        /// 获取所有医生
        /// </summary>
        /// <returns></returns>
        public List<M7_Employee> GetDoctorOrSpecialist()
        {
            return DAOFactory.GetDAO<EmployeeDAO>().ReadAllByDoctorOrSpecialist();
        }

        /// <summary>
        /// 根据唯一标识符获取员工信息
        /// </summary>
        /// <param name="uniqueId"></param>
        /// <returns></returns>
        public M7_Employee GetEmployee(string uniqueId)
        {
            return DAOFactory.GetDAO<EmployeeDAO>().Read(uniqueId);
        }

        /// <summary>
        /// 添加员工
        /// </summary>
        /// <param name="employee">员工</param>
        /// <returns></returns>
        public int AddEmployee(M7_Employee employee)
        {
            object result = DAOFactory.GetDAO<EmployeeDAO>().Create(employee);
            return Convert.ToInt32(result);
        }

        /// <summary>
        /// 编辑员工
        /// </summary>
        /// <param name="employee">员工信息</param>
        /// <returns></returns>
        public int UpdateEmployee(M7_Employee employee)
        {
            return DAOFactory.GetDAO<EmployeeDAO>().Update(employee);
        }

        /// <summary>
        /// 删除员工
        /// </summary>
        /// <param name="employeeId">员工ID</param>
        /// <returns></returns>
        public int DeleteEmployee(long employeeId)
        {
            return DAOFactory.GetDAO<EmployeeGroupDAO>().Delete(employeeId);
        }

        /// <summary>
        /// 根据证件类型和证件号获取人员信息
        /// </summary>
        /// <param name="identityType">证件号类型ID</param>
        /// <param name="identityId">证件号</param>
        /// <returns></returns>
        public S7_Citizen GetCitizenByIdentityId(int identityTypeId, string identityId)
        {
            return DAOFactory.GetDAO<CitizenDAO>().GetCitizenByIdentityId(identityTypeId, identityId);
        }

        /// <summary>
        /// 获取所有个人信息
        /// </summary>
        /// <returns></returns>
        public List<S7_Citizen> GetCitizenList()
        {
            return DAOFactory.GetDAO<CitizenDAO>().ReadAll();
        }

        /// <summary>
        /// 添加个人信息
        /// </summary>
        /// <param name="citizen">个人信息</param>
        /// <returns></returns>
        public int AddCitizen(S7_Citizen citizen)
        {
            object result = DAOFactory.GetDAO<CitizenDAO>().Create(citizen);
            return Convert.ToInt32(result);
        }

        /// <summary>
        /// 编辑个人信息
        /// </summary>
        /// <param name="citizen">个人信息信息</param>
        /// <returns></returns>
        public int UpdateCitizen(S7_Citizen citizen)
        {
            return DAOFactory.GetDAO<CitizenDAO>().Update(citizen);
        }

        /// <summary>
        /// 删除个人信息
        /// </summary>
        /// <param name="citizenId">个人信息ID</param>
        /// <returns></returns>
        public int DeleteCitizen(string citizenId)
        {
            return DAOFactory.GetDAO<CitizenDAO>().Delete(citizenId);
        }

        /// <summary>
        /// 获取职务列表
        /// </summary>
        /// <returns></returns>
        public List<M7_Duty> GetDutyList()
        {
            return DAOFactory.GetDAO<DutyDAO>().ReadAll();
        }

        /// <summary>
        /// 获取职位等级列表
        /// </summary>
        /// <returns></returns>
        public List<M7_Competence> GetCompetenceList()
        {
            return DAOFactory.GetDAO<CompetenceDAO>().ReadAll();
        }

        /// <summary>
        /// 获取性别列表
        /// </summary>
        /// <returns></returns>
        public List<M7_Gender> GetGenderList()
        {
            return DAOFactory.GetDAO<GenderDAO>().ReadAll();
        }

        /// <summary>
        /// 获取证件类型
        /// </summary>
        /// <returns></returns>
        public List<M7_IdentityType> GetIdentityTypeList()
        {
            return DAOFactory.GetDAO<IdentityTypeDAO>().ReadAll();
        }


        public List<M7_FrequencyForRecipe> GetRecipeFrequencyList()
        {
            return DAOFactory.GetDAO<FrequencyForRecipeDAO>().ReadAll();
        }

        public List<M7_ApproachForRecipe> GetRecipeApproachList()
        {
            return DAOFactory.GetDAO<ApproachForRecipeDAO>().ReadAll();
        }
    }
}
